package com.itcpeng.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itcpeng.constant.MessageConstant;
import com.itcpeng.entity.PageResult;
import com.itcpeng.entity.QueryPageBean;
import com.itcpeng.entity.Result;
import com.itcpeng.pojo.CheckItem;
import com.itcpeng.service.CheckItemService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.ws.rs.POST;
import java.util.List;

@RestController
@RequestMapping(value = "/checkitem")
public class CheckItemController {

    @Reference
    private CheckItemService checkItemService;

    /**
     * 添加
     */
    @PostMapping(value = "/add")
    @PreAuthorize("hasAnyAuthority('CHECKITEM_ADD')")
    public Result add(@RequestBody CheckItem checkItem) {
        //调用业务
        checkItemService.add(checkItem);
        return new Result(true, MessageConstant.ADD_CHECKITEM_SUCCESS);
    }

    //分页模糊查询
    @PostMapping(value = "/findPage")
    public Result findPage(@RequestBody QueryPageBean queryPageBean) {
        PageResult<CheckItem> pageResult = checkItemService.findPage(queryPageBean);
        Result result = new Result(true, MessageConstant.QUERY_CHECKITEM_SUCCESS, pageResult);
        return result;
    }

    @PostMapping(value = "/delete")
    @PreAuthorize("hasAnyAuthority('CHECKITEM_DELETE')")
    public Result deleteById(int id) {
        checkItemService.deleteById(id);
        return new Result(true, MessageConstant.DELETE_CHECKITEM_SUCCESS);
    }


    @GetMapping(value = "/findById")
    public Result findById(int id) {
        //调用业务
        CheckItem checkItem = checkItemService.findById(id);
        return new Result(true, MessageConstant.QUERY_CHECKITEM_SUCCESS, checkItem);

    }

    @PostMapping(value = "/update")
    public Result update(@RequestBody CheckItem checkItem) {
        //调用业务
        checkItemService.update(checkItem);
        return new Result(true, MessageConstant.EDIT_CHECKGROUP_SUCCESS);
    }

    @GetMapping(value = "/findAll")
    public Result findA() {
        List<CheckItem> list = checkItemService.findAll();
        return new Result(true, MessageConstant.QUERY_CHECKITEM_SUCCESS,list);
    }


}
